package org.oschina.util;

import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

public class JsoupUtil {
	
	public final static Whitelist whiteList=Whitelist.relaxed();
	
	static
	{
		whiteList.addAttributes("table","class");
		whiteList.addAttributes("tr","class");
		whiteList.addAttributes("td","class");
		
		whiteList.addAttributes("div","class");
		whiteList.addAttributes("pre","class");
		whiteList.addAttributes("img","src");
	}

	/**
	 * 按照白名单过滤
	 * @param value
	 * @param whitelist
	 * @return
	 */
	public static String clean(String value,Whitelist whitelist)
	{
		return Jsoup.clean(value, whitelist);
	}
	
	/**
	 * 只允许字符串
	 * @param value
	 * @return
	 */
	public static String none(String value)
	{
		return clean(value,Whitelist.none());
	}
	
	/**
	 * 只允许基本标签
	 * @param value
	 * @return
	 */
	public static String relaxed(String value)
	{
		return clean(value,Whitelist.relaxed());
	}
	
	/**
	 * 按照自定义白名单清理
	 * @param value
	 * @return
	 */
	public static String clean(String value)
	{
		return clean(value,whiteList);
	}
}